package com.ldp.designpatterns.study.iterator;

import com.ldp.designpatterns.study.iterator.collection.ConcreteCollection;
import com.ldp.designpatterns.study.iterator.iterator.IteratorD;

/**
 * @ClassName IteratorTest
 * @Description TODO:迭代器模式 迭代器模式提供了一种统一的方法来遍历不同类型的集合
 * @Author lindipei
 * @Date 2023/10/18 11:16
 */
public class IteratorTest {
    public static void main(String[] args) {
        ConcreteCollection<String> collection = new ConcreteCollection<>();
        collection.addItem("Item 1");
        collection.addItem("Item 2");
        collection.addItem("Item 3");

        IteratorD<String> iterator = collection.createIterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
